package com.learning.spring.security.pwd.store.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

/**
 * ClassName: SecurityConfig
 * Description: 密码存储
 * Date: 2022/7/29 9:14
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
public class SecurityConfig {

    /**
     * 设计
     * - UserDetails 代表用户主体操作，MutableUserDetails 扩展了更新密码的操作
     * - UserDetailsService 接口负责获取 UserDetails 数据，框架提供基于内存与 Jdbc 的实现
     * - UserDetailsManager 接口负责管理 UserDetails，如创建、更新、删除、修改密码、判断用户是否存在
     * - UserDetailsPasswordService 修改用户密码
     *
     * 实现
     * 1. 内存存储 InMemoryUserDetailsManager
     * 2. JDBC存储 JdbcUserDetailsManager
     * 3. 自定义数据存储 UserDetailsService
     * 4. LDAP 存储： LDAP Authentication
     * */

    /**
     * 简单的自定义
     *
     * @param http
     * @return
     * @throws Exception
     */
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated();
        http.formLogin(withDefaults());
        return http.build();
    }

}
